import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLineEdit, QDesktopWidget, QVBoxLayout, QStackedWidget
from PyQt5.QtCore import QCoreApplication, pyqtSignal


class Example(QWidget):
    my_signal = pyqtSignal(str, int)  # 自定义信号，放在类中定义

    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        btn = QPushButton('点击我', self)
        btn2 = QPushButton('测试', self)
        btn1 = QPushButton('退出', self)

        btn.clicked.connect(self.on_click)  # 对象.信号.(槽函数)
        btn1.clicked.connect(QCoreApplication.instance().quit)


        btn2.clicked.connect(self.do_something)
        self.my_signal.connect(self.my_solt)

        btn.resize(btn.sizeHint())
        btn2.resize(btn2.sizeHint())
        btn1.resize(btn1.sizeHint())
        btn.move(50, 50)
        btn2.move(300, 50)
        btn1.move(200, 50)

        # 文本框
        edit1 = QLineEdit(self)
        edit1.setPlaceholderText("请输入账号")

        # center_pointer = QDesktopWidget().availableGeometry().center()
        # # print(center_pointer)
        # x = center_pointer.x()
        # y = center_pointer.y()
        #
        # a, b, width, hight = self.frameGeometry().getRect()
        #
        # self.move(x - width // 2, y - hight // 2)  # 这里要注意不可以小数
        '''
        QStackedWidget抽屉布局
        container = QVBoxLayout()垂直布局
        v1_layout = QHBoxLayout()水平布局
        container.addWidget(v1_layout)嵌套布局
        
        hobby = QGroupBox()组
        btn1 = QRadiButton("text")点选
        
        hobby.setlayout(v1_layout)
        '''

        self.setGeometry(700, 300, 500, 300)  # 设置起始图形位置
        self.setWindowTitle('PyQt5 示例')
        self.show()

    def on_click(self):
        print('按钮被点击了！')

    def do_something(self):  # 干活发的信号
        self.my_signal.emit('我是被接受的数据', 666)

    def my_solt(self, data, num):  # 干活收到的焯
        print("正在测试" + data)
        print(num)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())  # 事件循环
